<template>
  <div class="detail">
    <van-nav-bar title="标题" left-text="返回" right-text="按钮" left-arrow @click-left="onClickLeft" @click-right="onClickRight" />
    <!-- <detailContent :articles="articleDetail"></detailContent> -->
    <h1>{{ articleDetail.stem }}</h1>
    <div class="info">
      <span>{{ articleDetail.createdAt }}</span>
      <span>|</span>
      <span>{{ articleDetail.views }} 浏览量</span>
      <span>|</span>
      <span>{{ articleDetail.likeCount }} 点赞数</span>
    </div>

    <div class="qian">
      <img :src="articleDetail.avatar" alt="" />
      <span>{{ articleDetail.creator }}</span>
    </div>

    <div class="content">{{ articleDetail.content }}</div>
    <div class="collects">
      <CollectStart></CollectStart>
    </div>
    <div class="like">
      <LikeStart></LikeStart>
    </div>
  </div>
</template>

<script>
import CollectStart from '@/components/collectStart.vue'
import LikeStart from '@/components/likeStart.vue'
import axios from 'axios'
import { Toast } from 'vant'
export default {
  name: 'HmDetail',
  components: {
    CollectStart,
    LikeStart,
  },
  data() {
    return {
      articleDetail: [],
    }
  },
  created() {
    console.log(this.$route.query.id)
    this.selectData(this.$route.query.id)
  },
  methods: {
    onClickLeft() {
      alert('返回了')
      this.$router.go(-1)
    },
    onClickRight() {
      Toast('按钮')
    },

    async selectData(id) {
      const res = await axios({
        url: `http://interview-api-t.itheima.net/h5/interview/show/?id=${id}`,
        headers: {
          Authorization: `Bearer ${localStorage.getItem('token')}`,
        },
      })
      console.log(res)
      this.articleDetail = res.data.data
    },
  },
}
</script>

<style lang="less" scoped>
.qian {
  display: flex;
  align-items: center;

  img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
  }
}

.content {
  text-indent: 2em;
}
.detail {
  width: 100%;
  height: 100%;
  position: relative;
}
.collects {
  position: absolute;
  bottom: -350px;
  right: 30px;
}
.like {
  position: absolute;
  bottom: -350px;
  right: 100px;
}
</style>
